{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card" id="search-form">
  <div class="layui-card-body">
    <div class="layui-layer-title">搜索</div>
    <form class="layui-form layui-row layui-col-space16 layui-search-admin">
      <div class="layui-inline">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-inline">
          <input type="text" name="name" placeholder="商品名称" lay-affix="clear" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">商品状态</label>
        <div class="layui-input-inline">
          <select name="status">
            <option value="">商品状态</option>
            <option value="0">未审核</option>
            <option value="1">审核通过</option>
            <option value="2">审核拒绝</option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">供货商ID</label>
        <div class="layui-input-inline">
          <input type="text" name="sid" placeholder="供货商ID" lay-affix="clear" class="layui-input">
        </div>
        <a href="javascript:vodi(0)" class="layui-btn layui-btn-primary" onclick="chooseBusinessShow()">查找商户ID</a>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">添加时间</label>
        <div class="layui-inline" id="laydate-rangeLinked">
          <div class="layui-input-inline">
            <input type="text" name="time_start" autocomplete="off" id="table-search-date-start" class="layui-input" placeholder="开始日期">
          </div>-
          <div class="layui-input-inline">
            <input type="text" name="time_end" autocomplete="off" id="table-search-date-end" class="layui-input" placeholder="结束日期">
          </div>
        </div>
      </div>
      <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">搜索</button>
        <button type="reset" class="layui-btn layui-btn-primary">清空</button>
      </div>
    </form>
  </div>
</div>
<div class="layui-card">
  <div class="layui-card-body">
    <table id="goods" lay-filter="test"></table>
  </div>
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" onclick="reload()">
      刷新数据
    </button>
    <button class="layui-btn layui-btn-sm" onclick="location.href='{:url('excel')}'+urlEncode(datawhere)">
      导出数据
    </button>
  </div>
</script>
<script type="text/html" id="barDemo">
  <div class="layui-clear-space">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<!--    <a class="layui-btn layui-btn-xs" lay-event="more">-->
<!--      更多-->
<!--      <i class="layui-icon layui-icon-down"></i>-->
<!--    </a>-->
  </div>
</script>
<script>
  var tableIns
  var datawhere
  layui.use(function(){
    var table = layui.table;
    var dropdown = layui.dropdown;
    var laydate = layui.laydate;
    var form = layui.form;

    // 创建渲染实例
    tableIns = table.render({
      elem: '#goods',
      url:'{:url("index")}', // 此处为静态模拟数据，实际使用时需换成真实接口
      toolbar: '#toolbarDemo',
      defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示',
        layEvent: 'LAYTABLE_TIPS',
        icon: 'layui-icon-tips'
      }],
      height: 'full-200', // 最大高度减去其他容器已占有的高度差
      css: [ // 重设当前表格样式
        '.layui-table-tool-temp{padding-right: 145px;}'
      ].join(''),
      cellMinWidth: 80,
      totalRow: false, // 开启合计行
      page: true,
      pagebar: '#test-pagebar', // 分页栏模板
      cols: [[
        {type: 'checkbox', fixed: 'left'},
        {field:'goods_id', fixed: 'left', width:80, title: 'ID', sort: true},
        {field:'supply_name', fixed: 'left', width:80, title: '供货商', sort: true},
        {field:'leixing', width:150, title: '商品类型',totalRowText: ''},
        {field:'goods_name', width:150, title: '商品名称',totalRowText: ''},
        {field: 'original_img', title: '缩略图',templet:function(d){
          var html = '<img src="'+d.original_img+'" width="50" height="50"  onclick="showBigImage(this)" />';
          return html;
        }},
        {field:'market_price', width:80, title: '原价',totalRowText: ''},
        {field:'shop_price', width:80, title: '销售价',totalRowText: ''},
        {field:'cost_price', width:80, title: '成本价',totalRowText: ''},
        {field:'pv', width:80, title: 'PV',totalRowText: ''},

        {field:'on_time', title:'上架时间'},
        // {field: 'reg_time', title: '注册时间',sort: true,templet:function(d){ return date('Y-m-d H:i',d.reg_time)}},

        {fixed: 'right', title:'操作', width: 134, minWidth: 125,  templet: '<div><button class="layui-btn layui-btn-sm" onclick="choosegoods(\'{{d.goods_id}}\')">选择</button></div>'}
      ]],
      error: function(res, msg){
        console.log(res, msg)
      }
    });
    laydate.render({
      elem: '.demo-table-search-date'
    });
    // 搜索提交
    form.on('submit(demo-table-search)', function(data){
      var field = data.field; // 获得表单字段
      datawhere = field;
      // 执行搜索重载
      table.reload('goods', {
        page: {
          curr: 1 // 重新从第 1 页开始
        },
        where: field // 搜索的字段
      });
      //layer.msg('搜索成功<br>此处为静态模拟数据，实际使用时换成真实接口即可');
      return false; // 阻止默认 form 跳转
    });
  });

  function chooseBusinessShow(){
    layer.open({type:2,title:'选择会员',content:"{:url('Suppliers/choosesupply')}/args/promoter",area:['900px','600px'],shadeClose:true});
  }
  function choosebusiness(data){
    console.log(data);
    $('input[name="sid"]').val(data.id)
  }
  function choosegoods(id){
    var index = layer.load();
    $.post("{:url('choosegoods')}",{id:id},function(res){
      layer.close(index);
      var type = "{:input('type')}";
      if(type==2){
        window.parent.choosepro2(res.data,"{$Request.param.args}");
      }else{
        window.parent.choosegoods(res.data,"{$Request.param.args}");
      }
      var index = parent.layer.getFrameIndex(window.name);
      parent.layer.close(index);
    });
  }
</script>
</body>
</html>